<template>
	<view>
		<!-- 老师信息 -->
		<view class="teacher_info">
			<image class="teacher_img" :src="teacherInfo.avatarUrl"></image>
			<view class="teacher_detail">
				<view class="teacher_name">
					<view class="name">{{teacherInfo.nickName}}</view>
					<!-- 星级 -->
					<!-- <view>
						<image v-for="(item, index) in teacherInfo.level" :key="index" mode="heightFix" src="https://img-blog.csdnimg.cn/20210316154410292.png"></image>
					</view> -->
				</view>
				<!-- 职位 -->
				<view class="teacher_class">
					<view v-for="(item, index) in teacherInfo.classList" :key="index">
						<view class="class_title">{{item.type + '老师'}}</view>
					</view>
					<!-- <view class="class_list">
						<view v-for="(item, index) in classList" :key="index">
							{{item}}
						</view>
					</view> -->
				</view>
			</view>
		</view>
		
		<!-- 课程价格 -->
		<view class="class_info" v-for="(item, index) in teacherInfo.classList" :key="index">
			<view>{{item.name}}</view>
			<view class="class_price">
				<view>￥{{item.teacherWage ? item.teacherWage : '0.00'}}/节</view>
				<view class="class_editor" @click="changePop(index)">设置</view>
			</view>
		</view>
		
		<!-- 显示弹窗 -->
		<form v-if="showPop" @submit="submit">
			<view class="popup" @click="hidePop()"></view>
			<view style="display: flex; justify-content: center;">
				<view class="popup_contain">
					<view>修改金额</view>
					<view class="contain_price">
						<text>￥</text>
						<input focus="true" type="digit" name="price" adjust-position="false" :value="teacherInfo.classList[selectIndex].teacherWage"/>
						<button form-type="submit">确定</button>
					</view>
				</view>
			</view>
		</form>
		
	</view>
</template>

<script>
	import cloudbase from '@cloudbase/js-sdk';
	const db = cloudbase.database();
	const dbCmd = db.command;
	export default {
		data() {
			return {
				selectIndex: '',
				showPop: false,
				keyboardHeight: 0,
				teacherInfo: ''
			}
		},
		onLoad(item) {
			if(item){
				if(item.info){
					let info = JSON.parse(item.info);
					console.log(info);
					this.teacherInfo = info;
				}
			}
		},
		methods: {
			changePop: function(index){
				this.selectIndex = index;
				this.showPop = true;
			},
			hidePop: function(){
				this.showPop = false;
			},
			changeHeight: function(event){
				console.log(event.detail.height);
				this.keyboardHeight = event.detail.height*1;
			},
			submit: function(e){
				let price = e.detail.value.price;
				let index = this.selectIndex;
				this.showPop = false;
				// 设置报酬
				this.teacherInfo.classList[index].teacherWage = price;
				// 保存到数据库中
				db.collection('class').where({
					_id: this.teacherInfo.classList[index]._id
				}).update({
					teacherWage: price
				}).then(res=>{
					console.log(res)
				})
			}
		}
	}
</script>

<script module="tools" lang="wxs">
	function subContent(val) {
		if (val.length == 0 || val == undefined) {
			return '';
		}
		if(val.indexOf('初级') != -1) return val.split('初级')[0];
		else return val.split('高级')[0];
		
	}
	module.exports = {
		sub: subContent
	}
</script>

<style>
	page {
		background-color: #F3F5F7;
	}
	
	.teacher_info{
		margin: 10rpx 30rpx;
		padding: 50rpx 30rpx;
		background-color: #fff;
		border-radius: 24rpx;
		display: flex;
		/* justify-content: space-between; */
	}
	
	.teacher_img{
		width: 150rpx;
		height: 150rpx;
		border-radius: 50%;
		margin-right: 30rpx;
		
	}
	
	.teacher_detail{
		width: 450rpx;
		display: flex;
		flex-direction: column;
	}
	
	.teacher_name{
		margin: 15rpx 0rpx;
		display: flex;
	}
	
	.name{
		width: 150rpx;
	}
	
	.teacher_name image{
		height: 35rpx;
	}
	
	.teacher_class{
		font-size: 28rpx;
		color: #777;
		/* display: flex; */
	}
	
	.class_title{
		/* width: 150rpx; */
	}
	
	.class_list{
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
	}
	
	.class_list view{
		margin-right: 30rpx;
	}
	
	/* 课程价格 */
	.class_info{
		margin: 30rpx;
		padding: 20rpx 30rpx;
		background-color: #fff;
		border-radius: 24rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.class_price{
		font-size: 28rpx;
		color: #666;
	}
	
	.class_editor{
		color: #FD973F;
		display: flex;
		justify-content: flex-end;
	}
	
	.popup{
		width: 100%;
		height: 100%;
		position: fixed;
		background-color: rgba(0,0,0, 0.4);
		top: 0;
		display: flex;
		justify-content: center;
	}
	
	.popup_contain{
		position: fixed;
		width: 80%;
		height: 80px;
		bottom: 50%;
		background-color: #fff;
		border-radius: 24rpx;
		z-index: 999;
		padding: 5%;
	}
	
	.contain_price{
		display: flex;
		border-bottom: #ddd solid 1rpx;
		padding-bottom: 10rpx;
		margin: 30rpx 0rpx;
		align-items: center;
	}
	
	.contain_price text{
		font-size: 55rpx;
		font-weight: bold;
		margin-right: 20rpx;
	}
	
	.contain_price button{
		background-color: #FD973F;
		color: #fff;
		height: 70rpx;
		font-size: 30rpx;
		margin-right: 0rpx;
		align-items: center;
	}
</style>
